#include <stdio.h>
void sort(int a[], int n)
{	   	 	     	 
    int i, j, t, *p;
    for (i = 0; i < n - 1; i++)
    {	   	 	     	 
        p = a + i;
        for (j = i + 1; j < n; j++)
        {	   	 	     	 
            if (*p > *(a + j))
                p = a + j;
        }
        if (p != (a + i))
        {	   	 	     	 
            t = *(a + i);
            *(a + i) = *p;
            *p = t;
        }
    }
}	   	 	     	 
void addins(int a[], int b[], int c[], int n, int m)
{	   	 	     	 
    int i, j, k, l;
    int *p1 = a, *p2 = b , *p3 = c;
    i = j = k = 0;
    while (i < n && j < m)
    {	   	 	     	 
        if (*(p1 + i) <= *(p2 + j))
        {	   	 	     	 
            *(p3 + k) = *(p1 + i);
            i++;
        }
        else
        {	   	 	     	 
            *(p3 + k) = *(p2 + j);
            j++;
        }
        k++;
    }
    if (i == n)
    {	   	 	     	 
        for (l = j; l < m; l++)
        {	   	 	     	 
            *(p3 + k) = *(p2 + l);
            k++;
        }
    }
    if (j == m)
    {	   	 	     	 
        for (l = i; l < n; l++)
        {	   	 	     	 
            *(p3 + k) = *(p1 + l);
            k++;
        }
    }
}	   	 	     	 
main()
{	   	 	     	 
    int a[5] = {9, 78, 33, 12, 23};
    int b[8] = {1, 34, 63, 10, 5, 94, 39, 27};
    int c[13];
    int i, n, m;
    int *p1 = a, *p2 = b, *p3 = c;
    sort(a, 5);
    for (i = 0; i < 5; i++)
    {	   	 	     	 
        printf("%4d\n", *(p1 + i));
    }
    sort(b, 8);
    for (i = 0; i < 8; i++)
    {	   	 	     	 
        printf("%4d\n", *(p2 + i));
    }
    addins(b, a, c, 8, 5);
    for (i = 0; i < 13; i++)
    {	   	 	     	 
        printf("%4d", *(p3 + i));
    }
}	